import scrapy

class QuotesCookiesSpider(scrapy.Spider):
    name = "quotes_cookies"

    def start_requests(self):
        url = "https://quotes.toscrape.com/login"
        yield scrapy.Request(url, callback=self.login_parse)


        # url = "https://quotes.toscrape.com/"
        # yield scrapy.http.Request(url, callback=self.parse, dont_filter=True)

    def login_parse(self, response):
        csrf_token = response.xpath('//input[@name="csrf_token"]/@value').extract_first()
        print(csrf_token, "-------")

        url = "https://quotes.toscrape.com/login"
        yield scrapy.FormRequest(url,  formdata={
            'csrf_token': csrf_token,
            'username': 'admin',
            'password': '123456'
        }, callback=self.login_res_parse)

    def login_res_parse(self, response):
        state = response.xpath('//div[@class="col-md-4"]/p/a/text()').extract_first()
        print(state)
    # def parse(self, response):
    #     state = response.xpath('//div[@class="col-md-4"]/p/a/text()').extract_first()
    #     print(state)



